
import 'package:demo/empUtils/EMPColorUtils.dart';
import 'package:demo/empUtils/EMPThemeUtils.dart';
import 'package:flutter/material.dart';

class EMPButton extends StatelessWidget{

  final String text;
  final double fontSize;
  final Color? textColor;
  final Color? disabledTextColor;
  final Color? backgroundColor;
  final Color? disabledBackgroundColor;
  final double? minHeight;
  final double? minWidth;
  final VoidCallback? onPressed;
  final EdgeInsetsGeometry padding;
  final double radius;
  final BorderSide side;

  const EMPButton({
    super.key,
    required this.text,
    this.fontSize = 14.0,
    this.padding = const EdgeInsets.all(8.0),
    this.radius = 0,
    this.side = const BorderSide(),
    this.textColor,
    this.disabledTextColor,
    this.backgroundColor,
    this.disabledBackgroundColor,
    this.minHeight,
    this.minWidth,
    this.onPressed
  });

  @override
  Widget build(BuildContext context) {
    final bool isDark = context.isDark;
    return TextButton(
        onPressed: onPressed,
        style: ButtonStyle(
          // 文字颜色
          foregroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.disabled)) {
              return disabledTextColor ?? (isDark ? EMPColor.dark_text_disabled : EMPColor.text_disabled);
            }
            return textColor ?? (isDark ? EMPColor.dark_button_text : Colors.white);
          },
          ),
          // 背景颜色
          backgroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.disabled)) {
              return disabledBackgroundColor ?? (isDark ? EMPColor.dark_button_disabled : EMPColor.button_disabled);
            }
            return backgroundColor ?? (isDark ? EMPColor.dark_app_main : EMPColor.app_main);
          }),
          // 水波纹
          overlayColor: MaterialStateProperty.resolveWith((states) {
            return (textColor ?? (isDark ? EMPColor.dark_button_text : Colors.white)).withOpacity(0.12);
          }),
          // 按钮最小大小
          minimumSize: (minWidth == null || minHeight == null) ? null : MaterialStateProperty.all<Size>(Size(minWidth!, minHeight!)),
          padding: MaterialStateProperty.all<EdgeInsetsGeometry>(padding),
          shape: MaterialStateProperty.all<OutlinedBorder>(
            RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(radius),
            ),
          ),
          side: MaterialStateProperty.all<BorderSide>(side),
        ),
        child: Text(text, style: TextStyle(fontSize: fontSize),)
    );
  }


}